import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int num=(n*(n+1))/2;
        int[] arr=new int[num];
        for(int i=0;i<num;i++){
            arr[i]=sc.nextInt();
        }
        int count=0;
        int[][] arr1=new int[n][n];
        for(int i=0;i<n;i++){
            for(int j=0;j<i+1;j++){
                arr1[i][j]=arr[count];
                count++;
            }
        }
        int cnou=arr1[0][0];
        int i=0;
        int j=0;
        int[] arr2=new int[n];
        arr2[0]=arr1[0][0];
        while(i<n-1){
            if(arr1[i+1][j]<arr1[i+1][j+1]){
                arr2[i+1]=arr1[i+1][j+1];
                j=j+1;
            }else{
                arr2[i+1]=arr1[i+1][j];
            }
            cnou+=arr2[i+1];
            i++;
        }
        System.out.print(cnou);
        System.out.print("[");
        for(int m=0;m<n;m++){
            if(m==n-1){
                System.out.print(arr2[m]);
            }else {
                System.out.print(arr2[m] + "-->");
            }
        }
        System.out.print("]");
    }
}